import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        Solution s = new Solution();
        int[] input = new int[]{3,2,2,3};
        System.out.println(s.removeElement(input, 3));
        System.out.println(Arrays.toString(input));
        input = new int[]{0,1,2,2,3,0,4,2};
        System.out.println(s.removeElement(input, 2));
        System.out.println(Arrays.toString(input));
    }
}


class Solution {
    public int removeElement(int[] nums, int val) {
        int i = 0, j = 0;
        while (j < nums.length) {
            if(nums[j] == val){
                j++;
                continue;
            }
            if(i < j){
                nums[i] = nums[j];
            }
            i++; j++;
        }
        return i;
    }
}